<?php
include("database.class.php");

$db = new Database("../mysqlconfig.txt");
$link = $db->connectWithDb();

$id = (int)$_GET['id'];
if(intval($id)==0) {
	die("Nice try, go on hacking somewhere else :)");
}

$messages = $db->executeQuery($link, "SELECT * FROM messages WHERE userid=$id ORDER BY DATE DESC");

$user = $db->executeQuery($link, "SELECT * FROM users WHERE id=$id");
$user = $user['name'];

if($messages === true) {
	die("This user ($user) has not sent any message yet.");
}
echo "<h1>Messages of $user ($id)</h1><br><table>\n";
echo "<tr><th>Message</th> <th># Of times it has been said</th> <th>Date of last time (m-d-Y)</th></tr>";
foreach($messages as $msg) {
	echo "<tr><td>".$msg['message']."</td><td>".$msg['amount']."</td><td>".date("H:i:s m-d-Y",$msg['date'])."</td></tr>";
}
echo "</table>\n";


?>
